﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using PPI.Entities.Enumerator;
using PPI.General;

namespace PPI.Entities.Inspections
{
    public class EInspectionImage : EBaseImage
    {
        private EInspection m_Inspection;
        private EInspectionResult m_InspectionResult;

        public EInspection Inspection
        {
            get { return m_Inspection; }
            set { m_Inspection = value; }
        }

        public EInspectionResult InspectionResult
        {
            get { return m_InspectionResult; }
            set { m_InspectionResult = value; }
        }

        public EInspectionImage()
        :base()
        {
            m_Inspection = new EInspection();
            m_InspectionResult = new EInspectionResult();
            m_TypeName = PPI.Constants.K_INSPECTIONFOLDERNAME;
        }

        public override string GetPlacemarkId()
        {
            return "InspectionImage_" + Id.ToString();
        }

        public override string GenerateHTML()
        {
            string htmlImage = "";
            if (this.Inspection.DatabaseType == DatabaseTypes.Project || this.Inspection.DatabaseType == DatabaseTypes.None)
            {
                ConfigReader reader = ConfigReader.GetInstance();
                string mode = reader.ConectionMode;
                string directoryName = DirHelper.GetImageDirectory(this.Inspection.Id, Id);
                string fileName = this.Inspection.Id + "_" + Id;
                htmlImage =
                    "     <td><a href=\"#" + GetPlacemarkId() + ";balloon\"><img src=\"http://www.dev-poleposition.com/Deploy/WebSite2.1/ImagePreview.aspx?Type=2&mode=" +
                    mode + "&dn=" + directoryName + "&fn=" + fileName + "&w=" + Constants.k_PREVIEWIMAGEWIDTH + "&h=" + Constants.k_PREVIEWIMAGEHEIGHT + "\"></a></td>";
                
            }
            else
            {
                htmlImage = "     <td><a href=\"#" + GetPlacemarkId() + ";balloon\"><img src=\"" + ImageFile.FullName + "\"></a></td>";

            }
            //_Shtml.AppendLine("<td><a href=\"#" + GetPlacemarkId() + ";balloon\"><img border='1' height=" + Constants.k_PREVIEWIMAGEHEIGHT + " width=" + Constants.k_PREVIEWIMAGEWIDTH + " src=\"" + ImageFile.FullName + "\"></a></td>");
            return htmlImage;
           
        }

        public override string GetHtmlPlacemark()
        {
            string htmlImage = "";
            if (this.Inspection.DatabaseType == DatabaseTypes.Project || this.Inspection.DatabaseType == DatabaseTypes.None)
            {
                ConfigReader reader = ConfigReader.GetInstance();
                string mode = reader.ConectionMode;
                string directoryName = DirHelper.GetImageDirectory(this.Inspection.Id, Id);
                string fileName = this.Inspection.Id + "_" + Id;
                htmlImage =
                    "     <td><a href=\"http://www.dev-poleposition.com/Deploy/WebSite2.1/ImagePreview.aspx?Type=2&mode=" +
                    mode + "&dn=" + directoryName + "&fn=" + fileName +
                    "&w=0&h=0\"><img src=\"http://www.dev-poleposition.com/Deploy/WebSite2.1/ImagePreview.aspx?Type=2&mode=" +
                    mode + "&dn=" + directoryName + "&fn=" + fileName + "&w=0&h=0\"></a></td>";
                
            }else
            {
                htmlImage = "     <td><a href=\"#" + GetPlacemarkId() + ";balloon\"><img src=\"" + ImageFile.FullName + "\"></a></td>";
            }

            StringBuilder _Shtml = new StringBuilder();
            _Shtml.AppendLine("<table style='font-family:Verdana; font-size:10px;' border='0'>");
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td><a href=\"" + this.Inspection.GetPlacemarkId() + ";balloon\">Back</a></td>");
            _Shtml.AppendLine(" </tr>");
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine(htmlImage);
            _Shtml.AppendLine(" </tr>");
            _Shtml.AppendLine("</table>");
            return _Shtml.ToString();
        }
    }
}
